//
//  NSString+MD5.m
//  iosapp
//
//  Created by 唐敏 on 16/4/26.
//  Copyright © 2016年 sxsihe. All rights reserved.
//

#import "NSString+MD5.h"
#import "CommonCrypto/CommonDigest.h"
#import "NSData+Md5.h"

@implementation NSString (MD5)

- (NSString *)md5 {
    const char *cStr = [self UTF8String];
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    CC_MD5( cStr, (CC_LONG)strlen(cStr), digest );
    NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
        [result appendFormat:@"%02x", digest[i]];
    return result;
}

- (NSString *)md5String
{
	NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding];
	return [data md5String];
}

@end
